﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace SuperBall3D
{
    public static class Camera 
    {
        //static Vector3 camPosition = new Vector3(0.0f, 50.0f, 5000.0f); //replacing with camOffset calculation
        static readonly Vector3 CamPositionOffset = new Vector3(0f, 600f, 900f); //replace camPosition, used with targetPosition to compute camera location
        static readonly Vector3 CamTargetOffset = new Vector3(0, 30, 0); // offset from target to aim camera at
        static Vector3 camTargetPosition;
        static Vector3 camUpVector = Vector3.Up;
        static float aspectRatio;
        //static float speed;  this is not used
        //static Vector3 Angle = Vector3.Zero; not used
        //static Vector3 thirdPersonReference = new Vector3(0, 500, -500); this is not used.

        static Matrix viewMatrix; //= Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);

        /*static public Vector3 Position //replacing with camOffset
        {
            get { return camPosition; }
            set { camPosition = value; }
        }*/

        static public Vector3 Target
        {
            get { return camTargetPosition; }
            set { camTargetPosition = value; }
        }

        static Camera()
        {
        }

        static public void UpdateCam(GameTime gameTime, Vector3 playerPosition, float playerFacingDirection)
        {
            camTargetPosition = playerPosition;

            Matrix cameraFacingMatrix = Matrix.CreateRotationY(playerFacingDirection);
            Vector3 positionOffset = Vector3.Transform(CamPositionOffset, cameraFacingMatrix);
            Vector3 targetOffset = Vector3.Transform(CamTargetOffset, cameraFacingMatrix);

            Vector3 cameraPosition = camTargetPosition + positionOffset;

            Vector3 cameraTarget = camTargetPosition + targetOffset;

            viewMatrix = Matrix.CreateLookAt(cameraPosition, cameraTarget, camUpVector);
        }

        static public Matrix ViewMatrix
        {
            get
            { return viewMatrix; }
        }

        static public float AspectRatio
        {
            get { return aspectRatio; }
            set { aspectRatio = value; }
        }


        static public Matrix ProjectionMatrix
        {
            get
            { return Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), AspectRatio, 1.0f, 10000.0f); }
        }

    }
}
